home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / mmailp.idb / usr / lib / Zmail / samples / zscript / folderbt.zsc.z / folderbt.zsc
Encoding:
Text File  |  1997-01-22  |  1.4 KB  |  73 lines

  1. # Sample Z-Script functions: folder_to_button, walk_tree, folder_buttons, prompt_folder_buttons
  2. #                    button: Folder Buttons...
  3.  
  4. function folder_to_button() {
  5. #%
  6. #       folder_to_button foldername
  7. #
  8. # Convert a folder name into a button that opens that folder
  9. #%
  10.     if $# == 0
  11.     error "usage: $0 foldername"
  12.     return -1
  13.     endif
  14.     if ! -F $1
  15.     echo "$1 is not a folder"
  16.     return 0            # Don't break loops
  17.     endif
  18.     if ! $?suffix
  19.     set suffix = _
  20.     endif
  21.     set base = $1:t
  22.     if "$base" =~ *[0-9.]*
  23.     set suffix = "${suffix}x"
  24.     set cmdname = folder$suffix
  25.     else
  26.     set cmdname = $base
  27.     endif
  28.     cmd $cmdname "open $1"
  29.     button -n "$base" $cmdname
  30. }
  31.  
  32. function walk_tree() {
  33.     if $# < 2
  34.     return 0
  35.     endif
  36.     set next = $1
  37.     shift
  38.     if -e $next/.
  39.     foreach f ($next/*) 'walk_tree $f $*'
  40.     return 0
  41.     else
  42.     $* $next
  43.     endif
  44.     unset next
  45. }
  46.  
  47. function folder_buttons() {
  48. #%
  49. #       folder_buttons 
  50. #
  51. #  Create a button on the main window for each file in the folder directory.
  52. #%
  53.     if $# == 0
  54.     if ! $?folder
  55.         return -1
  56.     endif
  57.     set - $folder
  58.     endif
  59.     set recursive
  60.     walk_tree $1 folder_to_button
  61.     unset recursive
  62. }
  63.  
  64. function prompt_folder_buttons() {
  65.     ask \
  66. "Create a button on the main window for\neach file in your folder directory?"
  67.     if $status == 0
  68.     folder_buttons
  69.     unbutton "Folder Buttons ..."
  70.     endif
  71. }
  72. button -n "Folder Buttons..." prompt_folder_buttons
  73.